﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using SW.AuthOrize.Configuration;
using SW.AuthOrize.Web;

namespace SW.AuthOrize.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class AuthOrizeDbContextFactory : IDesignTimeDbContextFactory<AuthOrizeDbContext>
    {
        public AuthOrizeDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<AuthOrizeDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            AuthOrizeDbContextConfigurer.Configure(builder, configuration.GetConnectionString(AuthOrizeConsts.ConnectionStringName));

            return new AuthOrizeDbContext(builder.Options);
        }
    }
}
